<template>
  <div>
    <tool-bar nav="" title='整理sql'></tool-bar>
    <kv label="sql">
      <el-input type="textarea" v-model="$data.txt1" :rows="12"></el-input>
    </kv>

    <kv label="整理">
      <el-button @click="exec_click">整理⤵</el-button>
    </kv>

    <kv label="结果">
      <el-input type="textarea" v-model="$data.txt2" :rows="16"></el-input>
    </kv>

  </div>
</template>
<script setup>
/**
 * Created by CodeGenerator
 */



defineOptions({
  name: "query-json",
  inheritAttrs: true,
});

//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();


//定义data
const $data = reactive({"txt1": "", "txt2": "", "defValue": false, "nullable": true, "embed": []});


const $props = defineProps({});


const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue", "loaded"]);


const exec_click = function () {
  $data.txt2 = "";
  jv.$saveData("txt1", $data.txt1);

  if ($data.txt1.includes("flyway_schema_history")) {
    $data.txt2 = "导出表不能包含 flyway_schema_history !"
    return;
  }

  $data.txt2 = $data.txt1
      .replaceAll(/^\/\*.*\*\/;$/igm, "")
      .replaceAll(/\bDEFAULT\s+CHARSET=['"]?\w+['"]?/ig, "")
      .replaceAll(/\bCOLLATE=['"]?\w+['"]?/ig, "")
      .replaceAll(/\bCHARACTER\s+SET\s+['"]?\w+['"]?/ig, "")
      .replaceAll(/\bCOLLATE\s+['"]?\w+['"]?/ig, "")
      .replaceAll(/--.*/ig, "")
      .replaceAll(/\n\n+/ig, "\n\n")
};


onMounted(function () {
  jv.$loadData("txt1", v => $data.txt1 = v);
});

</script>

<style lang="scss" scoped>
::v-deep(.kv>.k) {
  flex: 1;
}

::v-deep(.kv>.v>:first-child) {
  max-width: unset;
}

.grid {
  position: relative;
  margin-left: 20px !important;
  margin-top: 20px !important;


  ::v-deep(textarea), ::v-deep(.el-col), ::v-deep(.el-textarea) {
    height: 100%;
  }
}

.op_column {
  padding-top: 150px;
  padding-bottom: 150px;
  display: flex;
  flex-wrap: wrap;
  place-content: center;
  align-content: space-around;
  position: relative;
  height: 100%;


  button {
    display: block;
    margin: 10px 6px;
  }

}
</style>